package com.zry.controller;

import com.zry.entity.BlogCategory;
import com.zry.service.blogCategoty.IBlogCategoryService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Optional;

/**
 * 首页
 * @author Zry
 */

@Controller
@Log4j2
public class IndexController {

    @Autowired
    private IBlogCategoryService blogCategoryService;

//    @GetMapping({"/","/index"})
//    public ModelAndView index(String cid){
//        ModelAndView modelAndView = new ModelAndView();
//        modelAndView.addObject("cid", Optional.ofNullable(cid).orElse("0"));
//        modelAndView.setViewName("index");
//        return modelAndView;
//    }

    @GetMapping({"/newindex"})
    public String newIndex(Model model){
        // 查询分类
        List<BlogCategory> categoryList = blogCategoryService.findBlogCategories();
        model.addAttribute("categoryList",categoryList);
        return "newindex";
    }

}
